<template>
	<view>
		<view class="container">
			<view class="title">姓名</view>
			<input class="inp-box" v-model="name" type="text" value="" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 60rpx;letter-spacing: 0rpx;color: #c3c3c3;"  placeholder="请输入您的姓名" />
			<view class="title">联系方式</view>
			<input class="inp-box" v-model="phone" type="number" value="" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 60rpx;letter-spacing: 0rpx;color: #c3c3c3;" placeholder="请输入手机号" />
			<view class="title">省/市/区</view>
			<input class="inp-box"  @tap="selecteaddress" disabled="true" type="text" :value="address" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 60rpx;letter-spacing: 0rpx;color: #c3c3c3;" placeholder="请选择省市区县" />
			<w-picker
				mode="region"
				:defaultVal="['安徽省','合肥市','蜀山区']"
				:areaCode="['34','3304','340104']"
				:hideArea="false"
				@confirm="onConfirm" 
				ref="region"
				:timeout="true"
			></w-picker>
			<view class="title">详细地址</view>
			<input class="inp-box" v-model="text" type="text" value="" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 60rpx;letter-spacing: 0rpx;color: #c3c3c3;" placeholder="请输入详细地址" />
			<view class="btn">
				<button type="primary" :style="btn_style" class="btn-pry" @tap="uPublishTap">提交</button>
			</view>
		</view>	
	</view>
</template>

<script>
	import wPicker from "../component/w-picker/w-picker.vue";
	var common = require('../../../utils/common.js');
	var app = getApp();
	var _this;

	export default {
		data() {
			return {
				village_id: 0,
				pigcms_id: 0,
				village_name: '',
				money: '',
				pay_name:'',
				url: '',
				actcolor:'',
				btn_style:'',
				
				name: '',
				phone: '',
				address:'',
				text: '',
				type: 0,
			}
		},
		onShow() {
			// #ifdef H5
			common.hideWxShare()
			// #endif
		},
		onLoad(options) {
			_this = this;
			_this.type = options.type;
			console.log("type",_this.type)
			// #ifdef H5
			console.log('准备跳小程序页', _this);
			common.webToMiniapp(_this.route, options, 'redirect')
			// #endif
			common.setMainColor(_this, function(config) {
				_this.actcolor = config.config.mobile_head_color
				_this.btn_style = 'background-color: ' + _this.actcolor + ';box-shadow:0px 30rpx 30rpx -30rpx ' + _this.actcolor + ';';
				const res = uni.getStorageSync('village_key');
				if (res) {
					_this.village_id = res.village_id;
					_this.pigcms_id = res.pigcms_id;
					_this.village_name = res.village_name;
				};
				
				if(options.type == 1){
					// 收
					const resdata = uni.getStorageSync('receive_key');
					if (resdata) {
						_this.name = resdata.receivename;
						_this.phone = resdata.receivephone;
						_this.text = resdata.receivetext;
						_this.address = resdata.receiveaddress;
					}
				}else{
					// 寄
					const resnum = uni.getStorageSync('send_key');
					if (resnum) {
						_this.name = resnum.name;
						_this.phone = resnum.phone;
						_this.text = resnum.text;
						_this.address = resnum.address;
					}
				}
			});
		
		},
		methods: {
			onConfirm(val){
				_this.address = val.result
				
				console.log("11111",_this.address);
			},
			selecteaddress(){
				this.$refs.region.show()
			},
			uPublishTap(){
				if(_this.type == 0){
					// 寄
					var name = _this.name;
					var phone = _this.phone;
					var text = _this.text;
					const resdata = {
						name: name,
						phone: phone,
						address: _this.address,
						text: text,
					} 
					uni.setStorageSync("send_key",resdata)
					if(name && phone && _this.address && text){
						uni.navigateBack()
					}else{
						uni.showModal({
							title: common.changeTxt('提示'),
							content: common.changeTxt('请添加快递信息'),
							showCancel: false,
							confirmText: common.changeTxt('确定'),
							success: function(res) {
								if (res.confirm) {
									
								}
							}
						});
					}
				}else{
					// 收
					console.log("收")
					var name = _this.name;
					var phone = _this.phone;
					var text = _this.text;
					const res = {
						receivename: name,
						receivephone: phone,
						receiveaddress: _this.address,
						receivetext: text,
					} 
					uni.setStorageSync("receive_key",res)
					if(name && phone && _this.address && text){
						uni.navigateBack()
					}else{
						uni.showModal({
							title: common.changeTxt('提示'),
							content: common.changeTxt('请添加快递信息'),
							showCancel: false,
							confirmText: common.changeTxt('确定'),
							success: function(res) {
								if (res.confirm) {
									
								}
							}
						});
					}
				}
			},
		},
		components: {
			wPicker
		},
	}
</script>

<style>
	page {
		background: rgb(245, 245, 245);
	}

	.container {
		margin: 0;
		padding: 0;
	}
	.top-head {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}
	.address-icon {
		width: 20rpx;
		height: 30rpx;
		margin-right: 15rpx;
	}
	.address-img {
		display: block;
		width: 100%;
		height: 100%;
	}
	.address-text {
		font-size: 28rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 100rpx;
		letter-spacing: 0rpx;
		color: #ffffff;
	}
	.title {
		margin-left: 30rpx;
		font-size: 26rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 50px;
		letter-spacing: 0rpx;
		color: #333333;
	}
	.inp-box {
		background: #FFFFFF;
		margin: 0rpx 30rpx;
		padding: 30rpx;
		border-radius: 10rpx;
	}
	.btn {
		margin: 74rpx 0rpx;
		height: 100%;
		width: 100%;
	}
	.btn-pry {
		width: 550rpx;
		height:98rpx;
		background: #2681f3;
		border-radius:49rpx;
		line-height: 98rpx;
		margin-top: 220rpx;
	}
</style>
